<?php
class Menu extends CI_Controller{

    var $url = 'menu/';

    function __construct(){
        parent::__construct();
        $this->lang->load('menu');
        $this->load->library('form_validation');
    }

    function grid(){
		$this->load->model('filtergrid');
		$grid = new Filtergrid($_GET);
		$grid->select('id','nombre','url_tab_content','parent','menu.order','menu_icon','tab_index','href','controller');
		$grid->from('menu');
		$grid->order_by('parent','asc');
		$grid->output('id');
    }

	function principal(){
		$data=array();
		$this->load->view('menu', $data);
	}

	function guardar(){
		$msj  ='';
		$error='';
		$idk  ='id';
		$table='menu';
		$d    = $this->input->post();

		$this->form_validation->set_rules('nombre'         , $this->lang->line("FORM_LABEL_NOMBRE")    , 'required|max_length[50]' );
		$this->form_validation->set_rules('url_tab_content', $this->lang->line("FORM_LABEL_URL")       , 'required|max_length[255]');
		$this->form_validation->set_rules('menu_icon'      , $this->lang->line("FORM_LABEL_ICON")      , 'required|max_length[255]');
		//$this->form_validation->set_rules('tab_index'      , $this->lang->line("FORM_LABEL_TAB_INDEX") , 'required|max_length[11]' );
		//$this->form_validation->set_rules('href'           , $this->lang->line("FORM_LABEL_HREF")      , 'required|max_length[50]' );
		//$this->form_validation->set_rules('controller'     , $this->lang->line("FORM_LABEL_CONTROLLER"), 'required|max_length[50]' );
		$this->form_validation->set_error_delimiters('', '</br>');

		$this->form_validation->run();
		$error     .=$this->load->view('validation_errors',array(),true);
		$array_error=$this->form_validation->array_errors();

		if(empty($error)){
			$resp  =guardar($table,$d,$idk,$d[$idk]);
			$error.=$resp['error'];
			$msj  .=$resp['mensaje'];
		}
		echo json_encode(array('error' => $error,'mensaje' => $msj,'id'=>array('key'=>$idk,'value'=>$d[$idk]),'array_error'=>$array_error));
	}
}

?>
